package com.wt.springsamples.tx;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 * TransactionInterceptor、DefaultAopProxyFactory
 */
@EnableTransactionManagement
@Configuration
@ComponentScan("com.wt.springsamples.tx")
public class TxConfig {

//    @Bean
//    public DataSource dataSource(){
//        String url = "jdbc:mysql://localhost:3306/testdb?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&useSSL=false";
//        HikariDataSource dataSource = new HikariDataSource();
//        dataSource.setJdbcUrl(url);
//        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
//        dataSource.setUsername("root");
//        dataSource.setPassword("root");
//        return  dataSource;
//    }

    @Bean
    public PlatformTransactionManager transactionManager(DataSource dataSource){
        PlatformTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
        return transactionManager;
    }

//    @Bean
//    public  ITxService txServiceProxy(){
//        return  new TxServiceProxy();
//    }

//    @Bean
//    public  ITxService txService(){
//        return  new TxService();
//    }

}
